package com.camera2.local;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

public class SharedPrefer {

    public static void SaveToken(Context context, String token){
        SharedPreferences sp = context.getSharedPreferences("Userinfo",
                Context.MODE_PRIVATE);
        Editor editor = sp.edit();
        editor.putString("token", token);
        editor.commit();
    }

    public static String ReadToken(Context context) {
        SharedPreferences sp = context.getSharedPreferences("Userinfo",
                Context.MODE_PRIVATE);
        String token = sp.getString("token", "");
        return token;

    }


    public static void SaveLongitude(Context context, double longitude){
        SharedPreferences sp = context.getSharedPreferences("Userinfo",
                Context.MODE_PRIVATE);
        Editor editor = sp.edit();
        editor.putFloat("longitude", (float)longitude);
        editor.commit();
    }

    public static double ReadLongitude(Context context) {
        SharedPreferences sp = context.getSharedPreferences("Userinfo",
                Context.MODE_PRIVATE);
        float longitude = sp.getFloat("longitude", 0);
        return longitude;

    }

    public static void SaveLatitude(Context context, double latitude){
        SharedPreferences sp = context.getSharedPreferences("Userinfo",
                Context.MODE_PRIVATE);
        Editor editor = sp.edit();
        editor.putFloat("latitude", (float) latitude);
        editor.commit();
    }

    public static double ReadLatitude(Context context) {
        SharedPreferences sp = context.getSharedPreferences("Userinfo",
                Context.MODE_PRIVATE);
        float latitude = sp.getFloat("latitude", 0);
        return latitude;

    }

    public static void SaveCity(Context context, String city){
        SharedPreferences sp = context.getSharedPreferences("Userinfo",
                Context.MODE_PRIVATE);
        Editor editor = sp.edit();
        editor.putString("city", city);
        editor.commit();
    }

    public static String ReadCity(Context context) {
        SharedPreferences sp = context.getSharedPreferences("Userinfo",
                Context.MODE_PRIVATE);
        String city = sp.getString("city", "");
        return city;

    }


    public static void Saveid(Context context, String appid){
        SharedPreferences sp = context.getSharedPreferences("Userinfo",
                Context.MODE_PRIVATE);
        Editor editor = sp.edit();
        editor.putString("id", appid);
        editor.commit();
    }

    public static String Readid(Context context) {
        SharedPreferences sp = context.getSharedPreferences("Userinfo",
                Context.MODE_PRIVATE);
        String appid = sp.getString("id", "");
        return appid;

    }

    public static void SaveUsername(Context context, String username){
        SharedPreferences sp = context.getSharedPreferences("Userinfo",
                Context.MODE_PRIVATE);
        Editor editor = sp.edit();
        editor.putString("username", username);
        editor.commit();
    }

    public static String ReadUsername(Context context) {
        SharedPreferences sp = context.getSharedPreferences("Userinfo",
                Context.MODE_PRIVATE);
        String username = sp.getString("username", "");
        return username;

    }


    public static void SavePassword(Context context, String password){
        SharedPreferences sp = context.getSharedPreferences("Userinfo",
                Context.MODE_PRIVATE);
        Editor editor = sp.edit();
        editor.putString("password", password);
        editor.commit();
    }

    public static String ReadPassword(Context context) {
        SharedPreferences sp = context.getSharedPreferences("Userinfo",
                Context.MODE_PRIVATE);
        String password = sp.getString("password", "");
        return password;

    }

    public static void SaveUserExpert(Context context, int userExpert){
        SharedPreferences sp = context.getSharedPreferences("Userinfo",
                Context.MODE_PRIVATE);
        Editor editor = sp.edit();
        editor.putString("userExpert", userExpert+"");
        editor.commit();
    }

    public static int ReadUserExpert(Context context) {
        SharedPreferences sp = context.getSharedPreferences("Userinfo",
                Context.MODE_PRIVATE);
        String userExpert = sp.getString("userExpert", "");
        return Integer.parseInt(userExpert) ;

    }
}
